<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Func_Permit_Model extends CI_Model
{
	function __construct() 
	{
		parent::__construct();
	}
	function get_list_func_by_permit($permission_id)
	{
		if($permission_id!=0){
			$this->db->where('permission_id',$permission_id);
		}
		return $this->db->get('sys_permission_detail')->result();
	}
	function get_permission_by_id()
	{
	  $function_id = $this->uri->segment(3);
	  $this->db->where('permission_id',$function_id);
	  return $this->db->get('sys_permission')->row();
	} 
	
	function get_all_permission()
	{
		return $this->db->get('sys_permission')->result();
	} 
	function get_permit_by_id($function_id)
	{
		$this->db->where('permission_id',$function_id);
		return $this->db->get('sys_permission')->row();
	}
	function get_func_by_id($id)
	{
		return $this->db->get_where('sys_permission_detail',array('function_id'=>$id))->row();
	}
	
	function save()
	{
		$function_id = (int)$this->uri->segment(4);
		$permission_id = (int)$this->input->post('permission_id');
		$check = $this->get_permit_by_id($permission_id);
		$permission_name = $check->permission_name;
		$data = array(
			'permission_id' => $permission_id,
			'permission_name' => $permission_name,
			'function_name' => $this->input->post('function_name'),
			'function_notice' => $this->input->post('function_notice')
		);
		if($function_id!=0){
			$this->db->where('function_id',$function_id);
			if($this->db->update('sys_permission_detail',$data)){
				return true;
			}else{
				return false;
			}
		}else{
			if($this->db->insert('sys_permission_detail',$data)){
				return true;
			}else{
				return false;
			}
		}
		
	}      
}  
?>
